package online.hxstar.cloud.web.config;

import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author xinghu
 * @date 2019/9/6 3:31 下午
 */
@Configuration
public class WebAppConfigurer implements WebMvcConfigurer {

	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		//登录拦截的管理器
		InterceptorRegistration registration = registry.addInterceptor(new RequestInterceptor());
		//拦截的对象会进入这个类中进行判断
		registration.addPathPatterns("/*");
		//所有路径都被拦截
		registration.excludePathPatterns("/", "/login", "/error", "/static/**", "/logout");
		//添加不拦截路径

	}

	@Bean
	public FilterRegistrationBean<RequestAgainFilter> setFilter() {
		FilterRegistrationBean<RequestAgainFilter> filterBean = new FilterRegistrationBean<>();
		filterBean.setFilter(new RequestAgainFilter());
		filterBean.setName("RequestAgainFilter");
		filterBean.addUrlPatterns("/*");
		return filterBean;
	}
}
